package cn.trigram.example.designpattern.mediator;

/**
 * 中介者，接受colleague的通知，并协调调用负责处理通知的colleague
 * 可以与命令模式结合，通知变成命令，命令在与处理节点隔离
 */
public class Mediator {

  PersistentDB persistentDB;

  PersistentFile persistentFile;

  public Mediator setPersistentDB(PersistentDB persistentDB) {

    this.persistentDB = persistentDB;
    return this;
  }

  public Mediator setPersistentFile(PersistentFile persistentFile) {

    this.persistentFile = persistentFile;
    return this;
  }

  public void notifyOther(IPersistent persistent, Object data) {

		if (persistent instanceof PersistentDB) {
			persistentFile.getData(data);
		}
		if (persistent instanceof PersistentFile) {
			persistentDB.getData(data);
		}
  }

}
